package com.sunday.common.statemachine.study.e2_Config;

/**
 * TODO
 *
 * @author sunday
 * @since 2024/12/3
 */
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/pay")
    public String payOrder() {
        try {
            log();
            orderService.payForOrder();
            return "订单支付成功";
        } catch (Exception e) {
            return "订单支付失败: " + e.getMessage();
        }
    }

    @GetMapping("/ship")
    public String shipOrder() {
        try {
            log();
            orderService.shipOrder();
            return "订单发货成功";
        } catch (Exception e) {
            return "订单发货失败: " + e.getMessage();
        }
    }

    @GetMapping("/complete")
    public String completeOrder() {
        try {
            log();
            orderService.completeOrder();
            return "订单完成成功";
        } catch (Exception e) {
            return "订单完成失败: " + e.getMessage();
        }
    }

    @GetMapping("/cancel")
    public String cancelOrder() {
        try {
            log();
            orderService.cancelOrder();
            return "订单取消成功";
        } catch (Exception e) {
            return "订单取消失败: " + e.getMessage();
        }
    }

    private void log() {
        log.info("Action timeOutAction is running in thread: {}", Thread.currentThread().getName());
    }

}